<script setup lang="ts">
import { isMiniProgram } from "@/utils/mini-program";
import { useRouter, useRoute } from "vue-router";
import { useUserStore } from "./store/modules/user";
import VConsole from "vconsole";
import { useAppStore } from "./store/modules/app";
import wx from "weixin-js-sdk";

const router = useRouter();
const route = useRoute();
const userStore = useUserStore();
const appStore = useAppStore();

// 开启vConsole
appStore.enableVConsole && new VConsole();

// 配置nut-ui主题
const themeVars = reactive({
  primaryColor: "#3b82f6",
});

// 小程序返回按钮点击事件
const back = () => router.back();

// 记录分享者id
const watcher = watch(route, () => {
  const uid = route.query.uid as string;
  uid && userStore.updateShareUserId(uid);
  watcher();
});

document.title = userStore.tenantInfo?.platformName || "驾校服务平台";

// 是否在主页
const isHome = computed(() => router.currentRoute.value.matched?.[0]?.path === "/");
</script>

<template>
  <div>
    <nut-config-provider :theme-vars="themeVars">
      <router-view v-slot="{ Component }">
        <transition name="fade">
          <component :is="Component" :key="$route.fullPath" class="w-full" />
        </transition>
      </router-view>
    </nut-config-provider>
    <div
      v-if="isMiniProgram() && !isHome"
      @click="back"
      class="w-12 h-12 fixed z-1 bottom-35 right-3 bg-gray-300 flex justify-center items-center text-base rounded-full text-white opacity-65"
    >
      返回
    </div>
  </div>
</template>
